package com.example.service;

import cn.hutool.core.date.DateUtil;
import com.example.dao.LogDao;
import com.example.dao.NoticeDao;
import com.example.entity.Log;
import com.example.entity.Notice;
import com.example.entity.Params;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class NoticeService {
    @Resource
    private NoticeDao noticeDao;

    public void add(Notice notice){
        notice.setTime(DateUtil.now());
        noticeDao.insertSelective(notice);
    }

    public PageInfo<Notice> findBySearch(Params params) {
        //分页查询
        PageHelper.startPage(params.getPageNum(),params.getPageSize());

        List<Notice> list = noticeDao.findBySearch(params);
        return PageInfo.of(list);
    }

    public void delete(Integer id) {
        noticeDao.deleteByPrimaryKey(id);
    }

    public List<Notice> findAll() {
        return noticeDao.selectNotice();
    }
}
